/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {boolean}
 */
var isValidBST = function (root) {
  let arr = []
  function dfs(node) {
    if (!node) return

    dfs(node.left)
    arr.push(node.val)
    dfs(node.right)
  }
  dfs(root)

  //特殊情况处理（可以不写）
  // if (arr.length === 0 || arr.length === 1) return true

  //判断数组是否升序
  for (let i = 1; i < arr.length; i++) {
    if (arr[i] <= arr[i - 1]) return false
  }
  return true
};
